﻿#include "tfframe.h"
#include "ui_tfframe.h"
#include <QPainter>

TFFrame::TFFrame(QWidget *parent) :
    QFrame(parent),
    ui(new Ui::TFFrame)
{
    ui->setupUi(this);

    QPixmap pix  = GetNew(QImage("D:/examples/MixQmlWidget/header_61.png"));
    pix.save("mask.png");
}
QPixmap TFFrame::GetNew(QImage& img)
{
    img.convertToFormat(QImage::Format_ARGB32);
    //blank copy image
    QImage imageOut(img.size(),QImage::Format_ARGB32);
    //painter on it
    QPainter painter(&imageOut);
    //set opacity
    painter.setOpacity(0.5);
    painter.setBrush(Qt::white);
    painter.setPen(Qt::NoPen);
    //draw transparent image
    painter.drawImage(0,0,img);
    //set opacity
    painter.setOpacity(1);
    QPainterPath path(QPointF(0,0));
    //your mask - ellipse
    path.addEllipse(0,0,img.width(), img.height());
    painter.setClipPath(path);
    //draw untransparent part of image
    painter.drawImage(0,0,img);
    return QPixmap::fromImage(imageOut);
}
TFFrame::TFFrame(const TFFrame &other)
{

}

TFFrame::~TFFrame()
{
    delete ui;
}
